package com.srwl.mytx.map.trackutils;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.srwl.mytx.R;
import com.srwl.mytx.widget.datechoose.WheelView;
import com.srwl.mytx.widget.datechoose.adapter.AbstractWheelTextAdapter;

import java.util.ArrayList;

public class DateDialog extends Dialog implements
        View.OnClickListener {

    private CallBack back;
    private PriorityListener lis;
    private boolean scrolling = false;
    @SuppressWarnings("unused")
    private Context context = null;
    public Button softInfo = null;
    public Button softInfoButton = null;
    private  CalendarTextAdapter  yearAdapter = null;
    private CalendarTextAdapter monthAdapter = null;
    private CalendarTextAdapter dayAdapter = null;
    private Button btnSure = null;
    private Button btnCancel = null;
    private int curYear = 0;
    private int curMonth = 0;
    private int curDay = 0;
    private WheelView monthview = null;
    private WheelView yearview = null;
    private WheelView dayview = null;
    @SuppressLint("InlinedApi")
    private static int theme = android.R.style.Theme_Holo_Light_Dialog; // 主题
    // private static int theme = android.R.style.Theme_Black_NoTitleBar; // 主题


    private int flag = 0;
    //变量
    private ArrayList<String> arry_date = new ArrayList<String>();
    private ArrayList<String> arry_hour = new ArrayList<String>();
    private ArrayList<String> arry_minute = new ArrayList<String>();
    private ArrayList<String> arry_year = new ArrayList<String>();
    private int nowDateId = 0;
    private int nowHourId = 0;
    private int nowMinuteId = 0;
    private int nowYearId = 0;
    private String mYearStr;
    private String mDateStr;

    public interface PriorityListener {
        public void refreshPriorityUI(String year, String month, String day,
                                      CallBack back);
    }

    public interface CallBack {
        public void execute();
    }

    public DateDialog(final Context context, final PriorityListener listener,
                      CallBack callback, int currentyear, int currentmonth,
                      int currentday,  int flag) {
        super(context, theme);
        this.context = context;
        lis = listener;
        back = callback;
        this.curYear = currentyear;
        this.curMonth = currentmonth;
        this.curDay = currentday;

        this.flag = flag;
    }

    public DateDialog(Context context, PriorityListener listener) {
        super(context, theme);
        this.context = context;
    }

    public DateDialog(Context context, String birthDate) {
        super(context, theme);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.date_select_wheel);
        btnSure = (Button) findViewById(R.id.confirm_btn);
        btnSure.setOnClickListener(this);
        btnCancel = (Button) findViewById(R.id.cancel_btn);
        btnCancel.setOnClickListener(this);
        yearview = (WheelView) findViewById(R.id.year);
        monthview = (WheelView) findViewById(R.id.month);
        dayview = (WheelView) findViewById(R.id.day);
        if (flag != 1) {
            btnSure.setText("下一步");
        } else {
            btnSure.setText("确定");
        }

    }



    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.confirm_btn:
               // lis.
//                        refreshPriorityUI(yearAdapter.getValues(),
//                        monthAdapter.getValues(), dayAdapter.getValues(), back);

                this.dismiss();
                // if (flag != 1) {
                // showTime();
                // }
                break;
            case R.id.cancel_btn:
                this.dismiss();
                break;
            default:
                break;
        }
    }
    private class CalendarTextAdapter extends AbstractWheelTextAdapter {
        ArrayList<String> list;

        protected CalendarTextAdapter(Context context, ArrayList<String> list, int currentItem, int maxsize, int minsize) {
            super(context, R.layout.item_birth_year, R.id.tempValue, currentItem, maxsize, minsize);
            this.list = list;
        }

        @Override
        public View getItem(int index, View cachedView, ViewGroup parent) {
            View view = super.getItem(index, cachedView, parent);
            return view;
        }

        @Override
        public int getItemsCount() {
            return list.size();
        }

        @Override
        protected CharSequence getItemText(int index) {
            String str = list.get(index) + "";
            return str;
        }
    }
    @Override
    public void dismiss() {
        super.dismiss();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

}
